package com.radiant.data.entity;

import java.util.List;

import org.apache.commons.beanutils.ConvertUtilsBean;

import com.radiant.data.entity.DevelopmentTrack.Height;
import com.radiant.data.entity.DevelopmentTrack.TrackItem;
import com.radiant.data.entity.DevelopmentTrack.Weight;

public class DevelopmentTrackDAOImpl extends SimpleDBDAO<DevelopmentTrack> implements DevelopmentTrackDAO {

	public DevelopmentTrackDAOImpl() {
		super(DevelopmentTrack.class);
	}

	@Override
	protected void registerConverters(ConvertUtilsBean convertUtilsBean) {
		convertUtilsBean.register(TrackItem.getConverter(), TrackItem.class);
		convertUtilsBean.register(Height.getConverter(), Height.class);
		convertUtilsBean.register(Weight.getConverter(), Weight.class);
	}

	public DevelopmentTrack findByChildAndMonth(String childId, Month month) {
		StringBuffer whereClause = new StringBuffer();
		whereClause.append("childId = ").append("'").append(childId).append("'");
		whereClause.append(" AND ");
		whereClause.append("month = ").append("'").append(month).append("'");
		List<DevelopmentTrack> track = query(whereClause.toString(), null, 0, false);
		if (!track.isEmpty()) {
			return track.get(0);
		} else {
			return null;
		}
	}

}
